package com.andong.controller;

import com.andong.annotations.AccessControl;
import com.andong.domain.entity.VehicleBooking;
import com.andong.domain.pojo.Result;
import com.andong.service.VehicleBookingService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import static com.andong.utils.SystemConstant.*;

/**
 * 车辆预约表(VehicleBooking)表控制层
 *
 * @author makejava
 * @since 2024-01-20 11:08:58
 */
@RestController
@RequestMapping("vehicleBooking")
public class VehicleBookingController {
    /**
     * 服务对象
     */
    @Resource
    private VehicleBookingService vehicleBookingService;

    @PostMapping
    @AccessControl(roles = STUDENT)
    public Result insert(@RequestBody VehicleBooking vehicleBooking) {
        return vehicleBookingService.insert(vehicleBooking);
    }

    @GetMapping("/list")
    @AccessControl(roles = {STUDENT, COACH, ADMIN, SUPER_ADMIN}, permission = "预约管理")
    public Result list(@RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer pageSize) {
        return vehicleBookingService.getListBy(page, pageSize);
    }

    @DeleteMapping("/{id}")
    @AccessControl(roles = STUDENT)
    public Result delete(@PathVariable("id") Long id) {
        return vehicleBookingService.delete(id);
    }

    @PutMapping("/status")
    @AccessControl(roles = {COACH, ADMIN, SUPER_ADMIN}, permission = "预约管理")
    public Result updateStatus(Long id, Integer status, String rejectReason) {
        return vehicleBookingService.updateStatus(id, status, rejectReason);
    }
}

